# -*- coding: utf-8 -*-

'''
Created on 26/11/2011

@author: Luis M. Ugalde
www.forondarena.net

Copyright © 2011 Luis M. Ugalde
Licensed under the terms of the MIT License
(see LICENSE file for details)

This software can't be considered to be even in Alpha state. It still needs a lot of work.
'''


import sys
from statestores.statestoreexception import StateStoreException


class StateStore(object):
    '''
    StateStore facade-like structural pattern.
    '''


    def __init__(self, statestoretype, availablestatestores, *args, **kwargs):
        '''
        self.availableclasses = {'StateStoreRedis': ssredis.StateStoreRedis ,
                        'StateStoreShelve': ssshelve.StateStoreShelve
                        }
        '''        

        self.availableclasses = availablestatestores

        try:
            module, klass = self.availableclasses[statestoretype].split(".")
            _tmpmodule = __import__(module, globals(), locals(), [], 1)
            self.statestore = getattr(sys.modules['statestores.' + module], klass)(*args, **kwargs)
        except TypeError:
            raise StateStoreException('AbstractStateStore interface must be fully implemented')
        except KeyError:
            raise StateStoreException('State Store type is invalid')
        except ImportError:
            raise StateStoreException('Cant import required module')


    def setSource(self, *args, **kwargs):
        '''
        '''
        self.statestore.setSource(*args, **kwargs)


    def connectSources(self, *args, **kwargs):
        '''
        '''
        self.statestore.connectSources(*args, **kwargs)


    def setNotifySource (self, *args, **kwargs):
        '''
        '''
        self.statestore.setNotifySource(*args, **kwargs)


    def connectNotifySources(self, *args, **kwargs):
        '''
        '''
        self.statestore.connectNotifySources(*args, **kwargs)


    def setBindStateStore(self, *args, **kwargs):
        '''
        '''
        self.statestore.setBindStateStore(*args, **kwargs)
        
        
    def bindStateStore(self, *args, **kwargs):
        '''
        '''
        self.statestore.bindStateStore(*args, **kwargs)


    def setBindNotifyStateStore(self, *args, **kwargs):
        '''
        '''
        self.statestore.setBindNotifyStateStore(*args, **kwargs)
        
        
    def bindNotifyStateStore(self, *args, **kwargs):
        '''
        '''
        self.statestore.bindNotifyStateStore(*args, **kwargs)


    def processLines(self, *args, **kwargs):
        '''
        '''
        self.statestore.processLines(*args, **kwargs)


if __name__ == '__main__':
    print "Please, do not run this"
                    